/*
 * @Author: yangfan 1437446666@qq.com
 * @Date: 2023-02-27 21:42:25
 * @LastEditors: yangfan 1437446666@qq.com
 * @LastEditTime: 2023-03-03 15:58:32
 * @FilePath: \s_2006A_shixun\src\utils\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */

/**
 * @description:节流函数
 * @param {*fun:执行函数,time:延时}
 * @return {*节流函数}
 */
export const throttle = (function () {
  // 定时器
  let timer = null
  return (fun, time = 500) => {
    // 为空不执行
    if (timer) return
    // 执行函数
    fun()
    // 赋值
    timer = setTimeout(() => {
      // 赋值为空
      timer = null
    }, time)
  }
})()
/**
 * @description:防抖函数
 * @param {*fun:执行函数,time:延时}
 * @return {*节流函数}
 */
function debounce(fn, delay) {
  let t = null
  return function () {
    if (t !== null) {
      clearTimeout(t)
    }
    t = setTimeout(() => {
      fn.call(this)
    }, delay)
  }
}
